<?php
session_start();
class page {

	public $message; //error message
	public $title; //for title page
	public $content; //for content page

	function template ($tpl, $array=array()) {

		$file_path = "$tpl.html";
		switch(file_exists($file_path)) {
			case true:
				$template = file_get_contents($file_path);
				foreach ($array as $index => $var) {
					$template = str_replace("[[$index]]", $var, $template);
				}
				break;
			case false:
				die("Can't Get <i><b>$tpl's Template</b></i> !. Check The Template In Template Directory !");
				break;
		}
		return $template;

	}


	function show() { //make output to browser
		global $start;

		//Set The Array First, and then another...
		$array = array();
		$array["title"] = $this->title;
		$array["content"] = $this->content;
		if(isset($_SESSION["devxplorer"])) {
			$array["logout"] = "<a href='?do=logout'>Logout</a>";
		} else {
			$array["logout"] = "";
		}
		//Set templates, and then Print to browser
		$page = $this->template('template', $array);
		echo $page;
		exit;
	}
}

class file {

	public $path;

	function get() {
		if(is_file($this->path)) {
			$content = file_get_contents($this->path);
		} else {
			die("No Such File : ". $this->path);
		}
		return $content;
	}

	function write($content) {
		if(is_file($this->path)) {
			if(is_writable($this->path)) {
				$f = fopen($this->path, 'w');
				$result = fwrite($f, $content);
				fclose($f);
			} else {
				die("File Is Not Writeable !");
			}
		} else {
			die("No Such File");
		}
		return $result;
	}
}


?>